﻿using System.Collections;
using System.Collections.Generic;
using GameFramework;
using GameFramework.Fsm;
using GameFramework.Procedure;
using UnityEngine;
using UnityGameFramework.Runtime;
using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>;


public class ProcedureCrate:ProcedureBase
{

    bool isEnterGame = false;

    protected override void OnEnter(ProcedureOwner procedureOwner)
    {
        base.OnEnter(procedureOwner);
        SceneComponent scene = UnityGameFramework.Runtime.GameEntry.GetComponent<SceneComponent>();

        //先卸载之前得场景
        string[] loadedSceneAssetNames = scene.GetLoadedSceneAssetNames();//获取所有当前已经加载的场景
        for (int i = 0; i < loadedSceneAssetNames.Length; i++)
        {
            scene.UnloadScene(loadedSceneAssetNames[i]);//UnloadScene卸载场景的方法
        }

        //打开创建角色UI界面
        //加载UI组件
        UIComponent UI = UnityGameFramework.Runtime.GameEntry.GetComponent<UIComponent>();
        //加载UI

        UIFormConfig uiFormCfg = UIFormConfig.GetRowById((int)UIForms.CreatePlayer);
        UI.OpenUIForm(AppConsts.UIResPath + uiFormCfg.AssetName, uiFormCfg.UIGroupName, this);

        scene.LoadScene("CrateRole", this);//把场景名称传递进来


    }

    protected override void OnUpdate(ProcedureOwner procedureOwner, float elapseSeconds, float realElapseSeconds)
    {
        base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
        if (isEnterGame)
        {
            //SceneComponent scene = UnityGameFramework.Runtime.GameEntry.GetComponent<SceneComponent>();
            //scene.m_NextScene = "MainScene";
            //ChangeState<ProcedureChangeScene>(procedureOwner);
            ChangeState<ProcedureMainScene>(procedureOwner);
        }            
    }

    public void EnterGame()
    {
        isEnterGame = true;
    }
}
